
/**
 *外部调用 
 * @param {Object} url 全路径的服务器访问url,同get方式
 * @param {Object} callback 具体自定义的回调函数
 */


function callserver(url,callBack){
  var xmlHttpRequest = new CallXMLHttpRequest();
  xmlHttpRequest.complete=callBack;
  xmlHttpRequest.call(url);
}
/**
 * 自己定义回调函数,名字不同，参数相同
 * @param {Object} status
 * @param {Object} statusText
 * @param {Object} responseText
 * @param {Object} responseXML
 */
function callback(status,statusText,responseText,responseXML){
    //需要自己定义实现
}

function FactoryXMLHttpRequest(){
  if(window.XMLHttpRequest){
    return new XMLHttpRequest();
  }else if(window.ActiveXObject){
    var msxmls = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
    for(var i=0;i<msxmls.length;i++){
      try{
        return new ActiveXObject(msxmls[i]);
      }catch(e){
        
      }
    }
  }
  throw new Error("Could not instantiate XMLHttpRequest");
}

function CallXMLHttpRequest(){
  this._xmlhttp = new FactoryXMLHttpRequest();
}

function xmlHttpRequest_call(url){
  var instance = this;
  this._xmlhttp.open('GET',url,true);
  this._xmlhttp.onreadystatechange=function(){
    switch(instance._xmlhttp.readyState){
      case 1:
        instance.loading();
        break;
      case 2:
        instance.loaded();
        break;
      case 3:
        instance.interactive();
        break;
      case 4:
        instance.complete(instance._xmlhttp.status,instance._xmlhttp.statusText,instance._xmlhttp.responseText,instance._xmlhttp.responseXML);
        //removeLayer();
        instance = null;
        break;
    }
  }
  //createLayer();
  this._xmlhttp.send(null);
}

function xmlHttpRequest_loading(){
}

function xmlHttpRequest_loaded(){
}

function xmlHttpRequest_interactive(){
}

function xmlHttpRequest_complete(status,statusText,responseText,responseXML){
}

CallXMLHttpRequest.prototype.loading = xmlHttpRequest_loading;
CallXMLHttpRequest.prototype.loaded = xmlHttpRequest_loaded;
CallXMLHttpRequest.prototype.interactive = xmlHttpRequest_interactive;
CallXMLHttpRequest.prototype.complete = xmlHttpRequest_complete;
CallXMLHttpRequest.prototype.call = xmlHttpRequest_call;